<template>
  <div></div>
</template>

<script>
export default {
  mounted() {
    const goods_spec = [
      {
        isShowAdd: false,
        name: '颜色',
        value: ['红色', '蓝色']
      },
      {
        isShowAdd: false,
        name: '尺码',
        value: ['31', '33']
      },
      {
        isShowAdd: false,
        name: '套餐',
        value: ['套餐1', '套餐2']
      },
      {
        isShowAdd: false,
        name: '套餐',
        value: ['餐1', '餐2']
      },
      {
        isShowAdd: false,
        name: '套餐',
        value: ['餐1', '餐2']
      }
    ]
    const array = [9, 8, 7, 6, 5]
    const array2 = [
      { name: 'change', age: 12 },
      { name: 'change', age: 11 },
      { name: 'change1', age: 99 },
      { name: 'change', age: 17 },
      { name: 'change', age: 16 }
    ]
    const map1 = array.map((item, index, arr) => item * 100)
    const every = array.every((item, index, arr) => item >= 3)
    const some = array.some((item, index, arr) => item >= 3)
    const filter1 = array.filter((item, index, arr) => (item > 3 ? 10 : -1))
    const reduce1 = array.reduce((prev, item, index, arr) => prev + item, 90)
    const reduce2 = array.reduceRight(
      (prev, item, index, arr) => prev + item,
      90
    )
    const find = array2.find((item) => item.age === 99)
    const findIndex = array2.findIndex((item) => item.age === 99)
    // for (const index of array.keys()) {
    // }
    // for (const item of array.values()) {
    // }
    // for (const [item, index] of array.entries()) {
    // }
    // for (const v of array) {
    // }
    // const fruits = ['Banana', 'Orange', 'Apple', 'Mango', 'Kiwi', 'Papaya']
    const arrList = [1, [2, [3, 4, 5]]]
    const arrList2 = [1, 2, 3, 4, 5]
    const fla = function(arr) {
      let result = []
      for (let i = 0; i <= arr.length - 1; i++) {
        if (Array.isArray(arr[i]) === true) {
          result = result.concat(fla(arr[i]))
          // result = [result].concat([...fla(arr[i])])
        } else {
          result.push(arr[i])
        }
      }
      return result
    }
    const fla2 = function(arr) {
      return arr.reduce(
        (prev, item) =>
          prev.concat(Array.isArray(item) === true ? fla2(item) : item),
        []
      )
    }
    const fla3 = function(arr) {
      // return Array.prototype.toString.call(arr).split(',')
      return arr
        .join(',')
        .split(',')
        .map((item) => Number(item))
    }
    const fla4 = function(arr) {
      return arr.flat(Infinity)
    }
    // eslint-disable-next-line no-extend-native
    Array.prototype.push20 = function(arg) {
      console.log('arg', arg)
      const O = Object(this)
      const len = this.length
      const argLen = [...arguments].length
      if (len + argLen > 2 ** 53 - 1) {
        throw Error('over Max index')
      }
      for (let i = 0; i <= argLen - 1; i++) {
        O[len + i] = [...arguments][i]
      }
      return argLen + len
    }
    // eslint-disable-next-line no-extend-native
    Array.prototype.pop20 = function() {
      const O = Object(this)
      const item = O[0]
      if (this.length <= 1) {
        throw Error('array length small')
      }
      for (let i = 0; i < this.length; i++) {
        this[i] = this[i + 1]
      }
      this.length--
      return item
    }
    // eslint-disable-next-line no-extend-native
    Array.prototype.map20 = function(cb, thisValue) {
      const O = Object(this)
      const thats = thisValue
      const len = O.length
      const lenArray = new Array(len)
      for (let i = 0; i < lenArray.length; i++) {
        const value = O[i]
        const mapped = cb.call(thats, value, i, this)
        lenArray[i] = mapped
      }
      return lenArray
    }
    // eslint-disable-next-line no-extend-native
    Array.prototype.reduce20 = function(cb, initValue) {
      const O = Object(this)
      const len = O.length
      const lenArray = new Array(len)
      const init = initValue
      let changeValue = null
      if (init) {
        for (let i = 0; i < lenArray.length; i++) {
          changeValue = cb.call(
            undefined,
            i == 0 ? init : changeValue,
            O[i],
            i,
            this
          )
        }
      } else {
        for (let i = 0; i < lenArray.length; i++) {
          if (i === 0) {
            changeValue = O[i]
          } else {
            changeValue = cb.call(undefined, changeValue, O[i], i, this)
          }
        }
      }
      return changeValue
    }
    // eslint-disable-next-line no-extend-native
    Array.prototype.slice20 = function(start, end) {
      const O = Object(this)
      const len = O.length
      const endIndex = end ? end : len - 1
      const lenArray = new Array(len)
      const newArray = []
      for (let i = 0; i < lenArray.length; i++) {
        if (i >= start && i < endIndex) {
          newArray.push(O[i])
        }
      }
      return newArray
    }
    console.log(arrList2.slice20(1, 3))
    // console.log(arrList2.map20((item, index, arr) => ++item))

    // console.log(arrList2.reduce20((pre, item, index, arr) => item + pre))
    // console.log(arrList2.reduce((pre, item, index, arr) => {
    //   console.log(item, pre)
    //   return item + pre
    // }), 10)
  }
}
</script>

<style scoped></style>
